<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<c:set var="basePath" scope="request" value="<%=request.getContextPath()%>"/>
<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="renderer" content="webkit" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta http-equiv="pragma" content="no-cache" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection"content="telephone=no, email=no" />
    <title>新闻详情</title>
    <meta name="keywords" content="交广领航,河南交通广播" />
    <meta name="description" content="河南交通广播App" />
    <link rel="apple-touch-icon-precomposed" href="/pages/newsassets/css/img/logo.png" />
    <link rel="shortcut icon" type="image/icon" href="/pages/newsassets/css/img/favicon.ico" />
    <link rel="stylesheet" href="/pages/newsassets/css/global.css" />
    <link rel="stylesheet" href="/pages/newsassets/css/index.css">
</head>
<%-- <body>
    <form class="container" action="/demo/web/news/newspreview">
            <input type = "hidden" name = "id" id = "id" value="${id}">
            <input type = "hidden" name = "type" id = "type" value="${type}">
        <div class="article"></div>
 </form>
    
    <script src="/pages/newsassets/js/libs/jquery-2.1.4.js"></script>
    <script src="/pages/newsassets/js/libs/template.js"></script>
    <script type="text/html" id="template/container">
        <div class="nav">
            <p class="title">{{data.title}}</p>
            <div class="new-info">
                <span>分类:</span>
                <span>{{data.type}} </span>
                <span>{{data.date}}</span>
            </div>
        </div>
        <div class="article">{{data.content}}</div>
		<div class="orient"><a href="{{data.url}}">阅读原文</a></div>
    </script>
    <script>
        var App = {

            getData : function(){
                var url = $("form").attr('action');
                $.post(url, {}, function(result){
                    if(result){
                        var containerHtml = template('template/container', result);
                        $(".container").html(containerHtml);
                    }else{
                        alert("网络错误!");
                    }
                })
                .fail(function(){
                    alert("网络错误,请刷新重试！");
                });
            },

            initial : function(){
                this.getData();
            }
        }

        App.initial();
    </script>
</body>
</html> --%>
<body>
    
    <div id="container" class="container"  data-address="/demo/web/news/newspreview?id={id}&type={type}"></div>
    
    <script type="text/html" id="template/main">
        <p class="title">{{data.title}}</p>
        <div class="info">
            <span>分类：{{data.type_title}} &nbsp; {{data.t | timeFormat}}</span>
        </div>
        <div class="main">{{#data.content}}</div>
        <p><a href="{{data.url}}">来源：{{data.source}}</a></p>
    </script>
    <script src="/pages/newsassets/js/libs/jquery-2.1.4.js"></script>
    <script src="/pages/newsassets/js/libs/template.js"></script>
    <script>

        var App = {

            getParams : function(){
                var params = {};
                var str = location.search.substring(1);
                if (str.length > 0) {
                    var items = str.split('&');
                    $.each(items, function() {
                        var item = this.split('=');
                        var name = decodeURIComponent(item[0]);
                        var value = decodeURIComponent(item[1]);
                        if (name.length) params[name] = value;
                    });
                }
                return params;
            },

            templateHelp : function(){
                template.helper("timeFormat", function(t) {
                    if(typeof t !== "undefined"){
                        var time = new Date(t);
                        var y = time.getFullYear(),
                            m = time.getMonth() + 1,
                            d = time.getDate();
                        var date = y + '年' + m + '月' + d + '日';
                        return date;
                    }else{
                        return "时间格式不正确,请修正";
                    }
                });

                template.helper("formatContent", function(txt){
                    if(typeof txt === "undefined") return "文本字段为空!"
                    var content = txt.replace(/<br>/gm, '');
                    return content;
                });
            },

            getData : function(){
                var params = App.getParams();
                var dataURL = $("#container").attr('data-address');
                    dataURL = dataURL.replace(/{id}/, params.id);
                    dataURL = dataURL.replace(/{type}/, params.type);
                $.get(dataURL, {}, function(result, states, xhr){
                    if(result) {
                        var mainHtml = template('template/main', result);
                        $("#container").html(mainHtml);
                    }
                    else {
                        alert("请求失败,请刷新重试!");
                    }
                })
                .fail(function(){
                    alert("请求失败！");
                });
            },

            init : function(){
                this.templateHelp();
                this.getData();
            }
        };
        App.init(); 
    </script>
</body>
</html>